package com.acme.bankapp.domain.account;

import java.io.Serializable;


@SuppressWarnings("serial")
public abstract class AbstractAccount implements Account, Serializable {
	protected static final String MSG_AMOUNT_NONPOSITIVE = "Amount must be positive.";
	
	protected double balance;

	public AbstractAccount(final double balance) {
		this.balance = balance;
	}

	public void deposit(final double amount) {
		if (amount > 0) {
			this.balance += amount;
		} else {
			throw new IllegalArgumentException(MSG_AMOUNT_NONPOSITIVE);
		}
	}

	public double getBalance() {
		return this.balance;
	}
	
	public double getDecimalValue() {
		return Math.floor(balance);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(balance);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbstractAccount other = (AbstractAccount) obj;
		if (Double.doubleToLongBits(balance) != Double
				.doubleToLongBits(other.balance))
			return false;
		return true;
	}
}
